const express = require('express');
const router = express.Router();
const { protect } = require('../middleware/authMiddleware');
const {
  getExercises,
  getExerciseById,
  createExercise,
  updateExercise,
  deleteExercise,
  getWeeklyStats,
  getExerciseTypes
} = require('../controllers/exerciseController');

// 获取运动类型列表（公开）
router.get('/types', getExerciseTypes);

// 以下路由需要用户登录才能访问
router.use(protect);

// 获取运动记录列表和创建新记录
router.route('/')
  .get(getExercises)
  .post(createExercise);

// 获取每周运动统计
router.get('/stats/weekly', getWeeklyStats);

// 获取、更新、删除单个运动记录
router.route('/:id')
  .get(getExerciseById)
  .put(updateExercise)
  .delete(deleteExercise);

module.exports = router; 